<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>提交结果</title>
	<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateForm" target="_parent">
			<input type="hidden" id="rowId" name="rowId" value="${rowId}">
			<input type="hidden" id="platformTypeTemp" name="platformTypeTemp" value="">
			
			<div class="form-group" >
				<label class="col-xs-3 text-right">平台:</label>
				<div class="col-xs-7">
						<sk:select cssClass="form-control select" name="platformType" id="platformType" value="" requiredInit="true" ajaxURL="${sysManagerV1}/baseType/select?wm[PARENT_ID]=20" >
                            <option value="">请选择</option>
                        </sk:select>
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">项目:</label>
				<div class="col-xs-7" id="projectName">
						
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">账号:</label>
				<div class="col-xs-7" id="userName">
						
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">投票结果:</label>
				<div class="col-xs-7">
						<label><input name="optResult" type="radio" checked="checked"  value="1"/>&nbsp;成功</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<label><input name="optResult" type="radio"  value="2"/>&nbsp;失败</label>
				</div>
			</div>
			<div id="ticketNumFlag" class="form-group">
				<label class="col-xs-3 text-right">投票数:</label>
				<div class="col-xs-5">
					<input type="text" class="form-control" name="ticketNum" id="ticketNum" value="" maxlength = "20" placeholder="投票数">
				</div>
			</div>
			<div id="rechargeNumFlag" class="form-group">
				<label class="col-xs-3 text-right">充值ETH数量:</label>
				<div class="col-xs-5">
					<input type="text" class="form-control" name="rechargeNum" id="rechargeNum" value="" maxlength="7" placeholder="ETH数量">
				</div>
			</div>
			<div id="failReasonFlag"class="form-group" style="display: none;">
				<label class="col-xs-3 text-right">异常原因:</label>
				<div class="col-xs-5">
					<sk:select cssClass="form-control select" name="reasonTypeId" id="reasonTypeId" value="" requiredInit="true" ajaxURL="${sysManagerV1}/pubgBaseReasons/reasonSelect?reasonTypeId=13">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="failReason" id="failReason" value=""/>
                    
				</div>
			</div>
			<input type="hidden" id="isReCommit" value="0">
		</sk:form>
	</div>
</body>
   <%@ include file="/view/common/footer.jsp"%>
   <script type="text/javascript">
   
   	/* 获取头部信息 */
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return r[2];
        }
    };
   
       $(function(){
       
       		$(":radio").click(function(){
       			var optResult =  $(this).val();
			   if(optResult == 2 ){
			   	$("#ticketNumFlag").hide();
			   	$("#rechargeNumFlag").hide();
			   	$("#failReasonFlag").show();
			   }else{
			   	$("#ticketNumFlag").show();
			   	$("#rechargeNumFlag").show();
				$("#failReasonFlag").hide();
			   }
			  
			  });
       
           $('#rowId').val(GetQueryString('rowId'));
           
           var token = sessionStorage.getItem("token");
           var rowId = $('#rowId').val();
           //根据rowid 获取账号信息
           $.ajax({
           	url: "/cardUser/getUserDetail",
           	data: { token: token, rowId: rowId},
    		type:"post", 
    		dataType:'json',
    		success:function(data){
    			$('#platformType').val(data.data.platformType);
    			 $("#platformType").attr("disabled","true");
    			 $('#platformTypeTemp').val(data.data.platformType); // 回传到后台
    			 
    			 
    			$('#projectName').html(data.data.projectName);
    			$('#userName').html(data.data.userName);
    		}
           
           });
           
		   
           
       });

	//提交时验证
	//提交结果
	function submitResult() {
		var token = sessionStorage.getItem("token");
		var optResult =  $('input:radio:checked').val(); // 成功 失败
        var ticketNum = $('#ticketNum').val(); // 投票数量
        var rechargeNum = $('#rechargeNum').val(); // 充值数量
        var failReason = $('#failReason').val(); // 备注/异常原因       
        var platformType = $('#platformTypeTemp').val(); // 回传到后台 两个平台同时 后台会有问题，所以需要这个值
        var rowId = $('#rowId').val();
        if (rowId == null) {
            rowId = 0;
        }
        if(optResult == 1){
        	if (!CheckUtil.isNotNull(ticketNum)) {
				layer.msg("请填写投票数!");
				return;
			}
			if (!CheckUtil.isNotNull(rechargeNum)) {
				layer.msg("请填写充值ETH数量!");
				return;
			}
			var reasonTypeId = 0;
        }else if(optResult == 2){
        	var reasonTypeId = $.trim($("#reasonTypeId").val());
		    if (!CheckUtil.isNotNull(reasonTypeId)) {
		        layer.msg("请选择异常原因!");
		        return;
		    }
		    var failReason = $("#reasonTypeId").find("option:selected").text();
		    $("#failReason").val(failReason);
		     var ticketNum = 0 // 投票数量
        	 var rechargeNum = 0; // 充值数量
    
        }
		$.post(JSSYSMANAGERV1 + "/cardOptRecord/submit?token="+token+"&rowId="+rowId+"&resultCode="+optResult+"&ticket="+ticketNum+"&recharge="+rechargeNum+"&failId="+reasonTypeId+"&remark="+failReason+"&platformType="+platformType,function(result){
			if (result != null) {
				if (result.code == '1') {
					layer.msg("提交出错！");
					return;
				} else if (result.code == '0') {
                    layer.msg("提交成功！");
                    parent.findData();
                    parent.layer.close(parent.index);
					return;
				}
			}
		});
	}
   </script>
</html>